package org.pan.controller;

import org.apache.commons.lang.StringUtils;
import org.pan.service.CardUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.UUID;

/**
 * Created by panmingzhi on 2016/1/6.
 */
@Controller
@RequestMapping("/admin")
public class RootController {
    final String SIMPLE_RETURN_MESSAGE_FORMAT = "{success:\"%s\",msg:\"%s\"}";

    @RequestMapping("/login")
    public String login(){
        return "/admin/adminLogin";
    }

    @RequestMapping("")
    public String adminIndex(){
        return "/admin/adminLogin";
    }

    @ResponseBody
    @RequestMapping(value = "/doLogin",method = RequestMethod.POST)
    public String doLogin(@RequestParam("username") String username, @RequestParam("password") String password){

        if (StringUtils.isBlank(username) || StringUtils.isBlank(password)){
            return String.format(SIMPLE_RETURN_MESSAGE_FORMAT,"false","用户名与密码不能为空");
        }

        if (!username.equals("admin") || !password.equals("123456")){
            return String.format(SIMPLE_RETURN_MESSAGE_FORMAT,"false","用户名与密码不正确");
        }

        return String.format(SIMPLE_RETURN_MESSAGE_FORMAT,"true","登录成功");
    }

    @RequestMapping("/adminManager")
    public String adminManager(){
        return "/admin/adminManager";
    }
}
